import * as types from "./mutation-type";

const mutations = {
  // 改变loading状态
  [types.SET_LOADING](state, status) {
    state.isLoading = status;
  },
  // 账户余额
  [types.SET_BALANCE](state, data) {
    state.balance = data;
    localStorage.setItem("fn_m_balance", JSON.stringify(data));
  },
  // 是否登录
  [types.SET_LOGININFO](state, user) {
    if (user) {
      state.userInfo = user;
      localStorage.setItem("token", user.token);
      localStorage.setItem("fn_m_userInfo", JSON.stringify(user));
    } else if (user == null) {
      state.userInfo = null;
      localStorage.setItem("token", "");
      localStorage.setItem("fn_m_userInfo", null);
    }
  },
  // 是否显示Popup
  [types.SET_SHOW_POPUP](state, showPopup) {
    state.showPopup = showPopup;
  },
  // 改变当前Popup
  [types.SET_CURRENT_POPUP](state, popup) {
    if (popup.currentPopup === "download") {
      state.downloadTip = popup.downloadTip;
    }
    state.currentPopup = popup.currentPopup;
  },
};

export default mutations;
